<?php
class editAction extends rareAction{
	public function execute(){
		$id = $this->getGetParam('id',0);
		if($id == 0) forward('product/index');
		$productDao = new DaoProduct();
		$product = $productDao->getOne(" id = '$id'");
		$product['keyword'] = service_keyword::getNameByID($product['keyword']);
		$img = service_image::getOne(service_type::PRODUCT,$id);
		$this->assign('product',$product);
		$this->assign('images',array($img));
	}
	public function executePost(){
		$product = $this->getPostParam('p',array());
		$id = $this->getPostParam('id',0);
		$images = $this->getPostParam('img',array());
		$keyword = $this->getPostParam('keyword','');
		if(empty($product) || $id==0) jsonReturn(0,'修改失败');
		
		if($keyword!=''){
			$keywordID = service_keyword::save($keyword);
			$product['keyword'] = $keywordID;
		}
		$productDao = new DaoProduct();
		
		$now = date("Y-m-d H:i:s");
		$product['updateTime'] = $now;
		$productDao->update(" id = '$id'",$product);
		if(!empty($images)){
			service_image::insert($images,service_type::PRODUCT,$id);
		}
		jsonReturn(1,'ok');
	}
}
?>
